<!-- 管理单位查看抽签结果页面 -->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="项目名称" prop="extractItem">
        <el-input
          v-model="queryParams.extractItem"
          placeholder="请输入项目名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
			<el-form-item label="抽取人单位" prop="createBy">
				<el-select v-model="form.createBy" placeholder="请选择抽取人单位" clearable size="small" style="width:100%;" @change="UnitTypeChangepenson">
					<el-option v-for="type in unitTypeponsonOptions" :key="type.userId" :label="type.nickName" :value="type.userId" />
				</el-select>
			</el-form-item>
      <el-form-item label="抽取库" prop="randomUnittypeId">
        <el-select v-model="form.randomUnittypeId" placeholder="请选择单位库" clearable size="small" style="width:100%;" @change="UnitTypeChange">
          <el-option
            v-for="type in unitTypeOptions"
            :key="type.unittypeId"
            :label="type.unittypeName"
            :value="type.unittypeId"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="extractList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="项目名称" align="left" prop="extractItem" />
      <el-table-column label="建设地址" align="left" prop="extractAddress" />
      <el-table-column label="抽取人单位" align="left" prop="createBy" width="250"/>
      <el-table-column label="工程费用（万元）" align="left" prop="extractPrice" />
	  <el-table-column label="中介机构服务费（万元）" align="left" prop="maxPrice" />
      <el-table-column label="抽取库" align="left" prop="unitTypeName"/>
      <el-table-column label="审批状态" align="center" prop="extractApproveStatus" :formatter="approveStatusFormat" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="ResultOpentitle(scope.row)"
          >结果查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改项目申请对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="抽取库" prop="randomUnittypeId">
              <el-select v-model="form.randomUnittypeId" disabled='disabled' placeholder="请选择单位库" clearable size="small" style="width:100%;" @change="UnitTypeChange">
                <el-option
                  v-for="type in unitTypeOptions"
                  :key="type.unittypeId"
                  :label="type.unittypeName"
                  :value="type.unittypeId"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="抽取项目" prop="extractItem">
              <el-input v-model="form.extractItem" placeholder="请输入抽取项目" disabled='disabled'/>
              <el-input v-model="form.extractId" disabled='disabled' style="display:none;"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="抽取人" prop="extractUser">
              <el-input v-model="form.extractUser" placeholder="请输入抽取人" disabled='disabled'/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="抽取人单位" prop="extractUnit">
              <el-input v-model="form.extractUnit" placeholder="请输入抽取人单位" disabled='disabled'/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="排除要求" prop="extractBanReason">
          <el-input v-model="form.extractBanReason" type="textarea" placeholder="请输入内容" disabled='disabled'/>
        </el-form-item>
        <el-form-item label="备    注" prop="extractRemarks">
          <el-input v-model="form.extractRemarks" type="textarea" placeholder="请输入内容" disabled='disabled'/>
        </el-form-item>

        <!-- 库下对应单位表格 -->
        <el-table v-loading="loading" id="unitTable" :data="unitList">
          <el-table-column label="单位序号" align="center" prop="unitSort" />
          <el-table-column label="单位名称" align="center" prop="unitName" />
          <el-table-column label="资质等级" align="center" prop="unitNaturalGrade" />
          <el-table-column label="资质范围" align="center" prop="unitNaturalScope" />
          <el-table-column label="注册地址" align="center" prop="unitAddress" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                v-hasPermi="['unit:random:edit']"
              >禁用</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="extractAdd">抽 取</el-button>
        <el-button @click="cancel">重 置</el-button>
      </div>
    </el-dialog>

    <!-- 抽签过程展示窗口 -->
    <el-dialog :title="title" :visible.sync="extractOpen" width="500px" append-to-body>
      <img src="../../../assets/images/random.gif" class="user-avatar" style="height:200px;margin-left:25%;">
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">停 止</el-button>
        <el-button @click="gifcancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 查看项目抽签结果对话框 -->
    <el-dialog :title="title" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
     <div class="topbox">
         <el-row :gutter="15">
           <el-col :span="12">
             <el-form-item label="抽取项目:" prop="extractItem">
               {{form.extractItem}}
             </el-form-item>
           </el-col>
           <el-col :span="12">
             <el-form-item label="建设地址:" prop="extractAddress">
               {{form.extractAddress}}
             </el-form-item>
           </el-col>
         </el-row>
         <el-row :gutter="15">
           <el-col :span="12">
             <el-form-item label="工程费用(万元):" prop="extractPrice">
               {{form.extractPrice}}
             </el-form-item>
           </el-col>
           <el-col :span="12">
             <el-form-item label="建设周期:" prop="extractPeriod">
               {{form.extractPeriod}}
             </el-form-item>
           </el-col>
         </el-row>
         <el-row :gutter="15">
           <el-col :span="12">
             <el-form-item label="负责人:" prop="extractCharge">
               {{form.extractCharge}}
             </el-form-item>
           </el-col>
           <el-col :span="12">
             <el-form-item label="联系电话:" prop="extractPhone">
               {{form.extractPhone}}
             </el-form-item>
           </el-col>
         </el-row>
     	</div>
     	<div class="btobox">
     		<el-row :gutter="15">
     			<el-col :span="12">
         <el-form-item label="暂定中介服务费（万元）:" prop="maxPrice">
           {{form.maxPrice}}
         </el-form-item>
     	</el-col>
     	<el-col :span="12">
         <el-form-item label="排除要求:" prop="extractBanReason">
           {{form.extractBanReason}}
         </el-form-item>
     	</el-col>
     	</el-row>
         <el-form-item label="备    注:" prop="extractRemarks">
           {{form.extractRemarks}}
         </el-form-item>
     	<el-row :gutter="15">
     		<el-col :span="12">
         <el-form-item label="限价表:">
           {{form.extractPriceUrl}}
         </el-form-item>
     	</el-col>
     	</el-row>
			<el-row :gutter="15">
				<el-col :span="12">
					<el-form-item label="签字表:">
						<img :src="form.extractSignUrl" @click="innerVisible = true" class="form-img-out" v-if="this.form.extractSignUrl !=null && this.form.extractSignUrl !=undefined && this.form.extractSignUrl !=''">
					</el-form-item>
				</el-col>
			</el-row>
		<el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="抽取人" prop="extractUser">
              {{form.extractUser}}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="抽取地点" prop="extractPlace">
              {{form.extractPlace}}
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="报价限制时间" prop="quoteEndTime">
          {{form.quoteEndTime}}
        </el-form-item>
		<el-dialog
		      width="30%"
		      :visible.sync="innerVisible"
		      append-to-body
			  class="form-dialog">
			<img :src="form.extractSignUrl" class="form-img-line">
		</el-dialog>
     	</div>


        <!-- 当前项目抽签结果情况表格 -->
        <el-table v-loading="loading" :data="randomResultList" @selection-change="handleSelectionChange">
          <el-table-column label="单位名称" align="center" prop="randomUnitName" />
          <el-table-column label="抽取时间" align="center" prop="createTime" />
          <el-table-column label="抽取状态" align="center" prop="randomBan" :formatter="randomBanFormat"/>
        </el-table>
      </el-form>
    </el-dialog>
	<!-- 查看项目抽签结果对话框 -->
	<el-dialog :title="title" :visible.sync="resultOpen" width="800px" append-to-body @close="closeTable">
		<el-form ref="form" :model="form" :rules="rules" label-width="120px" style="width: 700px;padding-left: 50px;">
			<table class="printTable" border="1" id="printMe" cellspacing="0" width="100%" height="800px">
				<caption align="top" style="margin-bottom:30px;font-size:24px;">
          {{form.unitTypeName === '施工单位' ? '重庆高新开发建设投资集团有限公司非公招项目施工单位抽选结果表' : '重庆高新开发建设投资集团有限公司中介机构抽取结果表'}}
        </caption>
				<tr>
					<td colspan="3" style="text-align: left"  height="40px" class="font-FangSong topfont noBorder title-font">申请单位：{{ form.createBy }}</td>
					<td colspan="2" style="text-align: right" class="topfont noBorder font-FangSong">日期：{{ form.createTime | dateTime }}</td>
				</tr>
				<tr>
					<th rowspan="3" width="80px" class="bigfont">
						项 目 基
						<br />
						本 情 况
					</th>
					<td width="120px" height="60px" class="small font-SimHei">项 目 名 称</td>
					<th colspan="3" class="input commonBorder font-FangSong">{{ form.extractItem }}</th>
				</tr>
				<tr>
					<td class="small font-SimHei">建 设 地 址</td>
					<th colspan="3" class="input commonBorder font-FangSong">{{ form.extractAddress }}</th>
				</tr>
				<tr>
					<td class="small font-SimHei">
						工 程 费 用
						<br />
						(万 元)
					</td>
					<th width="150px" class="input font-FangSong">{{ form.extractPrice }}</th>
					<td width="80px" class="small font-SimHei">建 设 周 期</td>
					<th class="input commonBorder font-FangSong">{{ form.extractPeriod }}</th>
				</tr>
				<tr>
					<th :rowspan="form.unitTypeName !== '施工单位' ? rowspanList : 4" class="bigfont">中 标<br />信 息</th>
					<td class="small font-SimHei">抽 取 库</td>
					<th class="input font-FangSong">{{ form.unitTypeName }}</th>
					<td class="small font-SimHei">暂定中介服务费（万元）</td>
					<th colspan="3" class="input commonBorder font-FangSong">{{ form.maxPrice }}</th>
				</tr>
				<tr v-if="form.unitTypeName !== '施工单位'">
					<td class="small font-SimHei">业 务 类 型</td>
					<th class="input font-FangSong">{{ form.extractBusinessType}}</th>
					<td class="small font-SimHei">抽 取 时 间</td>
					<th class="input commonBorder font-FangSong">{{ form.updateTime | dateTime }}</th>
				</tr>
				<tr>
	    <td colspan="4" height="60px" class="small commonBorder font-SimHei">中 标 单 位 列 表</td>
	  </tr>
				<tr>
					<td height="60px" class="small font-SimHei">序 号</td>
					<td class="small font-SimHei">单 位 名 称</td>
					<td width="120px" class="small font-SimHei">联 系 人</td>
					<td width="120px" class="small commonBorder font-SimHei">联 系 电 话</td>
				</tr>
				<tr v-if="items == ''">
					<th height="60px"></th>
					<th></th>
					<th></th>
					<th class="commonBorder"></th>
				</tr>
				<tr v-for="(item, index) in items" :key="item.id">
					<th height="60px" class="input font-FangSong">{{ index + 1 }}</th>
					<th class="input font-FangSong">{{ item.randomUnitName }}</th>
					<th class="input font-FangSong">{{ item.randomLinkman }}</th>
					<th class="input commonBorder font-FangSong">{{ item.randomPhone }}</th>
				</tr>
				<tr>
					<th rowspan="4" class="bigfont a1">
						参 与 抽
						<br />
						取 人 员
					</th>
					<td class="small font-SimHei">抽 取 地 点</td>
					<th class="input commonBorder font-FangSong" colspan="3">{{ form.extractPlace }}</th>
				</tr>
				<tr>
					<td class="small font-SimHei">现 场 抽 取 人</td>
					<th colspan="3" class="input commonBorder font-FangSong">{{form.extractUser}}</th>
				</tr>
				<tr>
					<td rowspan="2" class="small a1 font-SimHei">
						纪 检 监 察
						<br />
						人 员
					</td>
					<th colspan="3" rowspan="2" class="input commonBorder a1 font-FangSong"></th>
				</tr>
			</table>

			<el-button v-print="'#printMe'" type="primary" style="margin-top:10px;margin-left:90%">打 印</el-button>
		</el-form>
	</el-dialog>
  </div>
</template>

<script>
import { listExtract, getExtract, delExtract, addExtract, updateExtract, exportExtract,getLists } from "@/api/unit/extract";
import { listRandom, getRandom, delRandom, addRandom, updateRandom, exportRandom,getRandomresult } from "@/api/unit/random";
import { listUnit,randomlist, getUnit, delUnit, addUnit, updateUnit, exportUnit } from "@/api/unit/unit";
import { listUser } from '@/api/system/user';
import { listUnittype, getUnittype } from "@/api/unit/unittype";

export default {
  name: "Extract",
  components: {
  },
  data() {
    return {
		//打开预览
		innerVisible:false,
      // 遮罩层
      loading: true,
	  //动态控制rowspan
	  rowspanList: 5,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目申请表格数据
      extractList: [],
	  //循环表格数组
	  items: [],
      // 单位信息表格数据
      unitList: [],
      // 单位抽签表格数据
      randomList: [],
      //抽签结果表格数据
      randomResultList:[],

      // 单位类型字典
      unitTypeOptions: [],
			//抽取单位字典
			unitTypeponsonOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //抽取弹出层
      extractOpen:false,
      //项目抽签结果层
      resultOpen:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        extractItem: null,
        extractUser: null,
        extractUnit: null,
        extractApproveStatus: null,
        randomUnittypeId: null,
      },
	  // 查询抽签结果参数
	  resultqueryParams: {
	  	extractId: null,
	  },
      UnitqueryParams: {
        pageNum: 1,
        pageSize: 10,
        unitName: null,
        unitNaturalGrade: null,
        unitNaturalScope: null,
        unitType: null,
      },
      // 查询参数
      RandomqueryParams: {
        pageNum: 1,
        pageSize: 10,
        extractId: null,
        randomUnitId: null,
        annex: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        extractUser: [
          { required: true, message: "抽取人不能为空", trigger: "blur" }
        ],
        extractUnit: [
          { required: true, message: "抽取单位不能为空", trigger: "blur" }
        ],
        extractItem: [
          { required: true, message: "抽取项目不能为空", trigger: "blur" }
        ],
        randomUnittypeId: [
          { required: true, message: "抽取库不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    this.getList();
    listUnittype(this.unitTypeParams).then(response => {
        this.unitTypeOptions = response.rows;
      });
	  listUser().then(response => {
	  	this.unitTypeponsonOptions = response.rows;
	  });
  },
  methods: {
	  closeTable(){
		  this.reset();
		  this.getList();
	  },
    /** 查询项目申请列表 */
    getList() {
      this.loading = true;
	  this.queryParams.extractApproveStatus="7";
      listExtract(this.queryParams).then(response => {
        this.extractList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        extractId: null,
        extractItem: null,
        extractUser: null,
        extractUnit: null,
        extractRemarks: null,
        extractBanReason: null,
        extractScore: null,
        extractApproveStatus: "1",
        randomUnittypeId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
		randomUnittypeId:null
      };
      this.resetForm("form");
    },
    // 单位库类型翻译
    unitTypeFormat(row, column) {
      return this.selecttypeLabel(this.unitTypeOptions, row.randomUnittypeId);
    },
    //转换单位库类型
    selecttypeLabel(datas, value) {
      var actions = [];
      Object.keys(datas).some((key) => {
        if (datas[key].unittypeId == ('' + value)) {
          actions.push(datas[key].unittypeName);
          return true;
        }
      })
      return actions.join('');
    },
    approveStatusFormat(row, column){
     return this.getType(row,column);
    },
    /** 搜索按钮操作 */
    async handleQuery() {
    	this.loading = true;
    	this.queryParams.pageNum = 1;
    	this.queryParams.extractItem=this.queryParams.extractItem;
    	this.queryParams.extractApproveStatus = "7";
    	await getLists(this.queryParams).then(response => {
    			this.extractList = response.rows;
    			this.loading = false;
    	});
    },
    //单位选择select改变方法
    UnitTypeChange(value){
      this.queryParams.randomUnittypeId = value;
    },
		//抽取人单位
		UnitTypeChangepenson(value) {
			listUser().then(response => {
				for(var o=0;o<response.rows.length;o++){
					if(value == response.rows[o].userId){
						this.queryParams.createBy = response.rows[o].nickName;
					}
				}
			});
		},
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
	  this.reset();
	  this.getList();
    },
    //抽取动画取消
    gifcancel() {
      this.extractOpen = false;
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.extractId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 抽取按钮操作 */
    extractAdd() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.extractOpen = true;
        }
      });
    },
	//结果查看按钮操作
	async ResultOpentitle(row) {
		const extractId = row.extractId || this.ids;
		this.resultqueryParams.extractId = extractId.toString();
		await getRandomresult(this.resultqueryParams).then(response => {
			this.items = response.data;
			if(this.items.length<2){
				this.rowspanList == 5;
			}else{
				this.rowspanList = this.items.length + 4;
			}
		});
		await getExtract(extractId).then(response => {
			this.form = response.data;
			this.resultOpen = true;
			this.title = '';
		});
	},
    /** 抽签按钮操作 */
    handleUpdate(row) {
      this.reset();
      const extractId = row.extractId || this.ids
      getExtract(extractId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "项目单位抽签";
      });

      //查询单位table数据
      this.UnitqueryParams.unitType = row.randomUnittypeId;
      randomlist(this.UnitqueryParams).then(response => {
        this.unitList = response.rows;
        this.loading = false;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.extractOpen = false;
          if (this.form.extractId != null) {
            addRandom(this.form).then(response => {
              this.reset();
              this.open = false;
              this.msgSuccess("抽取成功");
            });
          } else {

          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const extractIds = row.extractId || this.ids;
      this.$confirm('是否确认删除项目申请编号为"' + extractIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delExtract(extractIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 单位抽取状态转换 */
    randomBanFormat(row, column) {
      if(row.randomBan == 0){
        return "中签"
      }else{
        return "排除"
      }
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有项目申请数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportExtract(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  },
  filters: {
  	dateTime(val) {
  		if (val) {
  			return val.substr(0, 10);
  		}
  	}
  }
};
</script>
<style lang="scss" scoped>
	  .topbox{
		  width: 100%;
		  box-shadow: 5px 5px 5px rgba(0,0,0,0.08);
	  }
	  .btobox{
		  width: 100%;
		  margin-top: 20px;
		  margin-bottom: 10px;
		  box-shadow: 5px 5px 5px rgba(0,0,0,0.08);
	  }
	  ::v-deep .el-table .cell{
	  	overflow:hidden;
	  	white-space:nowrap;
	  	text-overflow:ellipsis;
	  }
	  ::v-deep .el-table .cell:hover{
	  	white-space: normal;
	  }
	  .form-img-out{
	  	width: 130px;
	  	height: 130px;
	  }
	  .form-img-line{
	  	width: 500px;
	  	height: 500px;
	  }
	  .form-dialog{
	  	text-align: center;
	  }
	  .topfont {
	  	font-size: 16px;
	  	font-weight: 400;
	  }
	  .small {
	  	text-align: center;
	  	font-weight: 100;
	  	font-size: 16px;
	  }
	  .bigfont {
	  	font-size: 18px;
	  	font-weight: 100;
	  	text-align: center;
	  	font-family:FangSong;
	  }
	  .input {
	  	font-size: 16px;
	  	font-weight: 400;
	  }
	  ::v-deep .el-table .denger-row {
	  	background: #FFE4E1;
	  }
	  ::v-deep .el-date-editor{
	    margin-left: -4px;
	  }
	  .printTable{
	    border: unset;
	  }
	  .noBorder{
	    border: unset;
	  }
	  .commonBorder{
	    border-right: 1px solid #9a9a9a;
	  }
	  .a1{
	    border-bottom: 1px solid #9a9a9a;
	  }
	  .title-font{
	   font-family:FangSong;
	  }
	  .font-SimHei{
	    font-family:FangSong;
	  }
	  .font-FangSong{
	    font-family:FangSong;
	  }
	  .unitSort-box{
	  	text-align: left;
	  }
	  .unitSort-box li{
	  	margin-top: 5px;
	  }
</style>
